package com.zy.ems.common.enums;

import java.io.Serializable;

import com.zy.ems.common.util.StringUtils;

/**
 * 渠道枚举：1-国内现货 2-海外直邮。
 * 
 * @author Luffy
 *
 */
public enum Channel implements Serializable {
    INLAND("1", "国内现货"),
    OVERSEA("2", "海外直邮");

    private String code;

    private String name;

    private Channel(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return this.code;
    }

    public String getName() {
        return this.name;
    }

    /**
     * 返回渠道编码对应的名称。
     * 
     * @param code
     * @return
     */
    public static String getChannelName(String code) {
        Channel channel = getChannel(code);
        if (channel != null) {
            return channel.name;
        }
        return StringUtils.EMPTY;
    }

    /**
     * 返回渠道编码对应的枚举。
     * 
     * @param code
     * @return
     */
    public static Channel getChannel(String code) {
        for (Channel channel : values()) {
            if (channel.code.equals(code)) {
                return channel;
            }
        }
        return INLAND;
    }
}
